package server.main.config.BeanInsert.Beans;

import org.springframework.beans.factory.annotation.Autowired;
import server.main.config.springsecurity.config.CustomerFilterInvocationSecurityMetadataSource;
import server.main.mapper.PermissionMapper;
import server.main.pojo.Permission;
import server.main.utils.SpringBeanUtils;

import java.util.List;

/**
 * @auther MingHsZzz
 * @Date 2022/11/3  14:33
 * @project main
 * @description
 */
public class PermissionRefresh {
   @Autowired
   PermissionMapper permissionMapper;

   @Autowired
   GetLoginPage getLoginPage;

   public boolean setPermisiion(){
      List<Permission> allPermission = null; // 数据库中所有的资源信息
      allPermission = permissionMapper.getAllpermission();
      for (Permission permission : allPermission) {
         permission.setRoles(permissionMapper.getRoles(permission.getId()));
      }
      CustomerFilterInvocationSecurityMetadataSource bean = SpringBeanUtils.getBean(CustomerFilterInvocationSecurityMetadataSource.class);
      bean.setAllPermission(allPermission);
      bean.setLoginurls(getLoginPage.getlogin());
//      System.out.println();

//      System.out.println(allPermission);

      return true;
   }
}
